import xlwt
import xlrd
import xlutils.copy


class read_Excel(object):
    def read_excel(self, one):  # num是sheet的排序，config是第一个，所以是0， one是该sheet中有多少行
        # 打开当前目录中的测试用例文档，获取sheet页
        workBook = xlrd.open_workbook(r"D:\python\Scripts\project\testApi\testFile\开放平台硬件接口自动化测试用例.xls",
                                      formatting_info=True)
        sheetName = workBook.sheet_names()
        # print(sheetName)
        wb = xlutils.copy.copy(workBook)
        stn = wb.get_sheet(sheetName[0])
        # print(stn)
        style = xlwt.XFStyle()
        alignment = xlwt.Alignment()
        font = xlwt.Font()
        font.name = u'微软雅黑'
        borders = xlwt.Borders()
        # pattern = xlwt.Pattern()
        alignment.horz = 0x02
        alignment.vert = 0x01
        alignment.wrap = 1
        borders.left = xlwt.Borders.THIN  # 添加边框-虚线边框
        borders.right = xlwt.Borders.THIN  # 添加边框-虚线边框
        borders.top = xlwt.Borders.THIN  # 添加边框-虚线边框
        borders.bottom = xlwt.Borders.THIN  # 添加边框-虚线边框
        # pattern.pattern_fore_colour = 0x0A
        style.alignment = alignment
        style.borders = borders
        style.font = font
        # print(f"{i}线程执行了")
        # 按行，列定位excel，且取出对应的参数（url，header，data）作为请求参数
        # data, sheetName = t.readExcel(0)
        sheet_name = workBook.sheet_by_name(sheetName[0])
        url = sheet_name.cell(one, 4).value
        headers = eval(sheet_name.cell(one, 6).value)
        idNum = str(sheet_name.cell(one, 0).value)
        data = eval(sheet_name.cell(one, 7).value)
        # expectResult = json.loads(sheet_name.cell(one, 9).value)
        return url, data, headers
